#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    
    // 甲乙双方的胜平负次数
    int win_a = 0, draw_a = 0, lose_a = 0;
    int win_b = 0, draw_b = 0, lose_b = 0;
    
    // 甲乙双方各手势的获胜次数
    int win_a_c = 0, win_a_j = 0, win_a_b = 0;
    int win_b_c = 0, win_b_j = 0, win_b_b = 0;
    
    for (int i = 0; i < n; i++) {
        char a, b;
        cin >> a >> b;
        
        if (a == b) {
            // 平局
            draw_a++;
            draw_b++;
        } else if ((a == 'C' && b == 'J') || (a == 'J' && b == 'B') || (a == 'B' && b == 'C')) {
            // 甲胜
            win_a++;
            lose_b++;
            if (a == 'C') win_a_c++;
            else if (a == 'J') win_a_j++;
            else win_a_b++;
        } else {
            // 乙胜
            lose_a++;
            win_b++;
            if (b == 'C') win_b_c++;
            else if (b == 'J') win_b_j++;
            else win_b_b++;
        }
    }
    
    // 输出甲乙的胜平负次数
    cout << win_a << " " << draw_a << " " << lose_a << endl;
    cout << win_b << " " << draw_b << " " << lose_b << endl;
    
    // 找出甲获胜次数最多的手势
    char best_a = 'B';
    if (win_a_c > win_a_b || (win_a_c == win_a_b && 'C' < best_a)) best_a = 'C';
    if (win_a_j > max(win_a_c, win_a_b) || (win_a_j == max(win_a_c, win_a_b) && 'J' < best_a)) best_a = 'J';
    
    // 找出乙获胜次数最多的手势
    char best_b = 'B';
    if (win_b_c > win_b_b || (win_b_c == win_b_b && 'C' < best_b)) best_b = 'C';
    if (win_b_j > max(win_b_c, win_b_b) || (win_b_j == max(win_b_c, win_b_b) && 'J' < best_b)) best_b = 'J';
    
    cout << best_a << " " << best_b << endl;
    
    return 0;
}